Skip to content

Add WebSocket handler for Browser and Node #9191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: dl/live
Choose a base branch
from
Open

Conversation

dlarocque
Copy link
Contributor

@dlarocque dlarocque commented Jul 31, 2025

Adds a WebSocket handler with implementations in Browser and Node environments. This will be used for BiDi.

Changes:

  • WebSocketHandler:
    • Provides separate implementations for browser (BrowserWebSocketHandler) and Node (NodeWebSocketHandler).
    • Isolates environment-specific logic and ensures build tools can properly tree-shake.
  • Node Support:
    • The NodeWebSocketHandler uses the built-in global WebSocket available in Node >= 22.
    • Adds ws as a dev dependency for types and the mock test server (Node 22 doesn't support web socket servers).
  • Testing:
    • Adds unit tests for BrowserWebSocketHandler using a mocked window.WebSocket.
    • Adds "unit" (integration?) tests for NodeWebSocketHandler using a local MockWebSocketServer.
    • New test script test:node
  • Build Config:
    • Adds generateAliasConfig to the set of rollup helpers, and uses it for platform import aliasing.

@dlarocque dlarocque requested review from DellaBitta and hsubox76 July 31, 2025 21:43
@dlarocque dlarocque requested a review from a team as a code owner July 31, 2025 21:43
Copy link

changeset-bot bot commented Jul 31, 2025

⚠️ No Changeset found

Latest commit: 7098537

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dlarocque dlarocque changed the base branch from main to dl/live July 31, 2025 21:43
Copy link
Contributor

@hsubox76 hsubox76 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments for more but I'm leaning towards not offering this for Node given the complications and not being sure there's a big demand for it anyway. I feel really bad about that given the effort you've put into the Node implementation and the clever dead code trick but it might come back.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 1, 2025

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 1, 2025

@dlarocque dlarocque requested a review from hsubox76 August 6, 2025 14:48
@@ -159,6 +159,7 @@
"typescript": "5.5.4",
"watch": "1.0.2",
"webpack": "5.98.0",
"ws": "8.18.3",
Copy link
Contributor

@hsubox76 hsubox76 Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting rid of this, right?

Edit: Oh, you need it for the server for the test.

Edit 2: Should probably leave it in the package.json for the product package if it's not used anywhere else.

* limitations under the License.
*/

import { NodeWebSocketHandler } from './node/websocket';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? The rollup alias just replaces the node in the import path, it doesn't replace the name of the imported symbol, right? Isn't this supposed to be just WebSocketHandlerImpl or something and the exported symbol from node/websocket.ts and browser/websocket.ts both have the same name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants